using System;
using System.Data;
namespace AppToolKit.Data
{
	public class DbSchemaBuilder : IDbSchemaBuilder
	{
		public virtual DbSchema Build(DataTable schemaTable)
		{
			DbSchema dbSchema = new DbSchema();
			foreach (DataRow dataRow in schemaTable.Rows)
			{
				DbSchema.ColumnSchema columnSchema = new DbSchema.ColumnSchema();
				columnSchema.Name = dataRow["ColumnName"].ToString();
				columnSchema.DbType = Type.GetType(dataRow["DataType"].ToString());
				if (columnSchema.DbType == typeof(string))
				{
					columnSchema.Length = Convert.ToInt32(dataRow["ColumnSize"]);
				}
				dbSchema.Columns.Add(columnSchema.Name, columnSchema);
			}
			return dbSchema;
		}
	}
}
